<?php
namespace web\admin\controller;

use hdphp\route\Controller;

class Login extends Controller{
    private $db;
	public function __construct(){
		$this->db=new \system\model\User();
		define('THEME_NAME', 'view');
	}

	/**
	 * 登陆页面
	 */
	public function index(){
		if(IS_POST){
			if($this->db->login()){
				//如果登陆成功
				message('操作成功',u('index.index'),"success");
			}
			//如果登陆失败
			message($this->db->getError(),'back',"error");
		}
		View::make();
	}

	/**
	 * 验证码
	 */
	public function code(){
		Code::num(2)->make();
	}

	/**
	 * 修改密码
	 */
	public function changePass(){
		//如果成功
		if(IS_POST){
			if($this->db->changePass()){
				message('操作成功',"back","success");

			}
			message($this->db->getError(),'back',"error");
		}
		View::make();
	}
	/**
	 *退出
	 */
	public function out(){
		session_destroy();
		session_unset();
		go('index');
	}
}
